<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            height: 0;
        }
        
        body {
            height: 2000px;
            position: relative;
        }
        
        main {
            display: block;
            box-sizing: border-box;
            width: 1200px;
            height: 418px;
            /* border: 1px solid red; */
        }
        
        main img {
            width: 1200px;
            height: 409px;
        }
        
        .return_div {
            position: fixed;
            top: 70%;
            right: 20px;
            width: 80px;
            display: none;
            text-align: center;
            font-size: 80px;
            height: 80px;
            line-height: 100px;
            color: white;
            /* border: 1px solid red; */
            background: rgba(0, 0, 0, 0.5);
            cursor: pointer;
        }
    </style>
</head>

<body>
    <main>
        <img src="./img/网易1.png" alt="">
    </main>

    <div class="return_div">
        ^
    </div>
    <script src="animate.js"></script>
    <script>
        // 获取元素
        var return_btn = document.querySelector(".return_div");
        window.onscroll = debounce(window_scrool, 200);
        // 防抖
        function window_scrool() {
            var scroll = document.documentElement.scrollTop || document.body.scrollTop;

            if (scroll >= 200) {
                return_btn.style.display = "block";
                console.log(scroll);
            } else {
                return_btn.style.display = "none";
            }
        }
        return_btn.onclick = function() {
            animate(document, 0);
        }

        function debounce(fn, delay) {
            // 定义并初始化延时器
            var timer = null;

            return function() {
                // 判断是否有定时器
                if (timer) {
                    // 先销毁延时器，在开启延时器
                    clearTimeout(timer);
                    timer = setTimeout(fn, delay);
                } else {
                    timer = setTimeout(fn, delay);
                }
            }
        }
    </script>
</body>

</html>